CreateClientConVar("smelt_type","",true,true)
CreateClientConVar("smelt_amount",0,true,true)

include("shared.lua")

--Called when it's time to draw the entity.
--Return: Nothing
function ENT:Draw()
         self.Entity:DrawModel()
end

--Called when the SENT is spawned
--Return: Nothing
function ENT:Initialize()
end

--Return true if this entity is translucent.
--Return: Boolean
function ENT:IsTranslucent()
end

--Called when a save-game is loaded.
--Return: Nothing
function ENT:OnRestore()
end

--Called when the SENT thinks.
--Return: Nothing
function ENT:Think()
end


local numberset
local SmeltChoice
local DLabel2
local DNumberWang1
local DLabel1
local DComboBox1
local DButton1
local DButton2
local SmeltingMenu

function Smelt_Menu()





SmeltingMenu = vgui.Create('DFrame')
SmeltingMenu:SetSize(110, 240)
SmeltingMenu:SetPos(0, 100)
SmeltingMenu:SetTitle('Smelting')
SmeltingMenu:SetSizable(false)
SmeltingMenu:SetDeleteOnClose(true)
SmeltingMenu:MakePopup()

DLabel2 = vgui.Create('DLabel',SmeltingMenu)
DLabel2:SetPos(10, 140)
DLabel2:SetText('Smelt Amount')
DLabel2:SizeToContents()



DLabel1 = vgui.Create('DLabel',SmeltingMenu)
DLabel1:SetPos(10, 30)
DLabel1:SetText('Select Type...')
DLabel1:SizeToContents()
DLabel1:SetTextColor(Color(0, 0, 0, 255))



    SmeltChoice = vgui.Create('DMultiChoice',SmeltingMenu)
	SmeltChoice:SetSize(90, 20)
	SmeltChoice:SetPos(10, 50)
    function SmeltChoice:OnSelect(Index, Value, Data)	
		Update()
    end	
	
		SmeltInfo1 = vgui.Create('DLabel',SmeltingMenu)
		SmeltInfo1:SetPos(10, 90)
		SmeltInfo1:SetText('Copper Ore x'..LocalPlayer():GetNWInt("copper"))
		SmeltInfo1:SizeToContents()	
	
		SmeltInfo2 = vgui.Create('DLabel',SmeltingMenu)
		SmeltInfo2:SetPos(10, 105)
		SmeltInfo2:SetText('Iron Ore x'..LocalPlayer():GetNWInt("iron"))
		SmeltInfo2:SizeToContents()	

	
		SmeltInfo3 = vgui.Create('DLabel',SmeltingMenu)
		SmeltInfo3:SetPos(10, 120)
		SmeltInfo3:SetText('Titanium Ore x'..LocalPlayer():GetNWInt("titanium"))
		SmeltInfo3:SizeToContents()	
	
    SmeltChoice:AddChoice('Smelt Copper')
    SmeltChoice:AddChoice('Smelt Iron')
    SmeltChoice:AddChoice('Smelt Titanium')
    SmeltChoice:SetConVar("smelt_type")
	
	DNumberWang1 = vgui.Create('DNumberWang',SmeltingMenu)
	DNumberWang1:SetPos(10, 155)
	DNumberWang1:SetDecimals(0)
	DNumberWang1:SetFloatValue(0)
	DNumberWang1:SetFraction(0)
	DNumberWang1:SetConVar("smelt_amount")
	DNumberWang1.OnMouseReleased = function()  end
	DNumberWang1.OnValueChanged = function()  end
	
DButton2 = vgui.Create('DButton',SmeltingMenu)
DButton2:SetSize(70, 20)
DButton2:SetPos(10, 210)
DButton2:SetText('Cancel')
DButton2.DoClick = function()
	
	timer.Destroy("multismelt")

  end

DButton1 = vgui.Create('DButton',SmeltingMenu)
DButton1:SetSize(70, 20)
DButton1:SetPos(10, 180)
DButton1:SetText('Start')
DButton1.DoClick = function() 

	
	
	if LocalPlayer():GetInfoNum("smelt_amount") > 2 then
		Smelting =1
		timer.Create( "multismelt", 2.1, 0, function()	
		
			RunConsoleCommand("smelt_amount", math.Clamp(LocalPlayer():GetInfoNum("smelt_amount")-1,0,1000));
			LocalPlayer():ConCommand("smelt_shit") 
			timer.Simple( 2.1, Update)
		end)
	
	else
			LocalPlayer():ConCommand("smelt_shit")
	end
	
	timer.Simple( 2.1, Update)


end
	
		
	
end


function ENT:Think()
	
	if Smelting ==1 and LocalPlayer():GetInfoNum("smelt_amount")==0 then
		timer.Destroy("multismelt")
		Smelting=0
		end

end

usermessage.Hook("SmeltingMenu", Smelt_Menu)

function Update()
	SmeltInfo1:SetText('Copper Ore x'..LocalPlayer():GetNWInt("copper"))
	SmeltInfo1:SizeToContents()	
	SmeltInfo2:SetText('Iron Ore x'..LocalPlayer():GetNWInt("iron"))
	SmeltInfo2:SizeToContents()	
	SmeltInfo3:SetText('Titanium Ore x'..LocalPlayer():GetNWInt("titanium"))
	SmeltInfo3:SizeToContents()	
	
	if LocalPlayer():GetInfo("smelt_type") == "Smelt Copper" then
	DNumberWang1:SetMinMax( 1,LocalPlayer():GetNWInt("copper"))
	
	DNumberWang1:SetValue(math.Clamp(LocalPlayer():GetInfoNum("smelt_amount")-1,0,LocalPlayer():GetNWInt("copper")))
	
	elseif LocalPlayer():GetInfo("smelt_type") == "Smelt Iron" then
	DNumberWang1:SetMinMax( 1,LocalPlayer():GetNWInt("iron"))
	
	DNumberWang1:SetValue(math.Clamp(LocalPlayer():GetInfoNum("smelt_amount")-1,0,LocalPlayer():GetNWInt("iron")))
	
	elseif LocalPlayer():GetInfo("smelt_type") == "Smelt Titanium" then
	DNumberWang1:SetMinMax( 1,LocalPlayer():GetNWInt("titanium"))
	
	DNumberWang1:SetValue(math.Clamp(LocalPlayer():GetInfoNum("smelt_amount")-1,0,LocalPlayer():GetNWInt("titanium")))
	
	end
	
end